﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using EB.Inbox;
using Purchase;
using Eb.MessageBox;
using System.Drawing;
using System.Collections;
using FrameWorkMain;
using Eb.StockManagement;
public partial class Modules_TaskList : System.Web.UI.UserControl
{
    
    FrameWorkMain.FrameWorkMain framework = new FrameWorkMain.FrameWorkMain();
    Purchase.Purchase purchase = new Purchase.Purchase();
    EB.Inbox.Inbox inbox = new EB.Inbox.Inbox();
    InboxSearchCriteria advanceSearch = new InboxSearchCriteria();

    static string inboxType = string.Empty;
    static int uniqInbox = 0;
    string viewDate;
    string processedDate;
    static int rowIndex = 0;
    static int requestTypeId = 0;
    static int inboxLinkKey = 0;
    DataSet ds = new DataSet();

    [System.Web.Script.Services.ScriptMethod]
    [System.Web.Services.WebMethod]
    public static string[] GetEPSNItems()
    {
        System.Collections.Generic.List<string> items =
            new System.Collections.Generic.List<string>();

        //string[] feeds = new string[] 
        //{
        //    "http://sports.espn.go.com/espn/rss/nfl/news",
        //    "http://sports.espn.go.com/espn/rss/mlb/news",
        //    "http://sports.espn.go.com/espn/rss/ncf/news",
        //    "http://sports.espn.go.com/broadband/ivp/rss",
        //    "http://sports.espn.go.com/espn/rss/news"
        //};

        //string feedUrl = feeds[new Random().Next(feeds.Length)];
        return GetSyndicationItems();
    }



    /// <summary>
    /// 
    /// </summary>
    private static string[] GetSyndicationItems()
    {
        StockManagement stck = new StockManagement();
        //SELECT     ProductID, ProductName, ProductCode, ProductDescription, Stock, Type, ListPrice, Unit"+
        //  " FROM         ProductList
        DataSet ds = stck.GetProductDtls();
        System.Collections.Generic.List<string> items = new System.Collections.Generic.List<string>();
        // System.ServiceModel.Syndication.SyndicationFeed feed = 
        //  System.ServiceModel.Syndication.SyndicationFeed.Load(System.Xml.XmlReader.Create(feedUrl));

        // items.Add(string.Format("<span class='title'>{0}</span>", HttpUtility.HtmlEncode(feed.Title.Text)));
        if (ds.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                items.Add(string.Format("<span>{0} <a href='{1}'>{2}</a><span>", "Product Name", "Default3.aspx?dd=" + ds.Tables[0].Rows[i]["ProductID"].ToString(), HttpUtility.HtmlEncode(ds.Tables[0].Rows[i]["ProductName"].ToString() + ",\t\t" + "(Qty :" + ds.Tables[0].Rows[i]["Stock"].ToString() + ")")));

                if (items.Count > 5)
                {
                    break;
                }
            }
        }

        items.Add(string.Format("<span class='title'>{0}</span>", HttpUtility.HtmlEncode("www.google.com")));
        return items.ToArray();
    }                   

    protected void Page_Load(object sender, EventArgs e)
    {
       // ImageButton2.Enabled = false;
        txtDate.Enabled = false;
        //ImageButton1.Enabled = false;
        ddlSelect.Enabled = false;
        ddlRequestTypeAll.Enabled = false;
        txtDateOfCreation.Enabled = false;
        ddlStatus.Enabled = false;
        txtrequestor.Enabled = false;

        viewDate = DateTime.Now.ToString("MM/dd/yyyy");
        processedDate = DateTime.Now.ToString("MM/dd/yyyy");
        if (this.IsPostBack)
        {
            System.Threading.Thread.Sleep(100);
        }
        if (!IsPostBack)
        {
            Session["controlPath"] = null;
            Session["hasrequestLinkId"] = null;
            Session["requestTypeId"] = null;
            TabContainer1.ActiveTabIndex = 0;
            TabContainer1.CssClass = "blue";
            PopulateInBox();
            PopulateAllInbox();
            PopulateRequestType();
            PopulateStatus();
            ddlSelect.Items.Add("Between");
            ddlSelect.Items.Add("<=");
            ddlSelect.Items.Add(">=");
            ddlSelect.Items.Add("=");
            ddlSelect.Items.Insert(0, "-Select-");


        }
    }

    void PopulateRequestType()
    {
        DataSet requestTypeDS=inbox.GetRequestType();
        ddlRequestTypeAll.DataSource=requestTypeDS;
        ddlRequestTypeAll.DataValueField = "RequestTypeID";
        ddlRequestTypeAll.DataTextField = "RequestName";
        ddlRequestTypeAll.DataBind();
        ddlRequestTypeAll.Items.Insert(0, "-Select-");
    }

    void PopulateStatus()
    {
        DataSet requestTypeDS = inbox.GetInboxStatusList();
        ddlStatus.DataSource = requestTypeDS;
        ddlStatus.DataValueField = "Status";
        ddlStatus.DataTextField = "StatusNote";
        ddlStatus.DataBind();
        ddlStatus.Items.Insert(0, "-Select-");
    }

    protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
    {

        
    }
    void ClearRecentInBox()
    {
       // ucLoadUserControl1.Controls.Clear();
        ucLoadUserControl1.Visible = false;
        btnNext.Visible = false;
        btnPrevious.Visible = false;
        btnBackToinBox.Visible = false;
        grvInBox.Visible = true;
        PopulateInBox();
    }
    void ClearAllInbox()
    {
        pnl.Visible = true;
      //  pnl.Controls.Clear();
        GridView1.Visible = true;
        btnNext1.Visible = false;
        btnPrevious1.Visible = false;
        btnBackToinBox1.Visible = false;
        PopulateAllInbox();
    }
    void PopulateInBox()
    {
        int userId = 0;
        if (Session["UserId"] != null)
            userId = Convert.ToInt16(Session["UserId"].ToString());
        DataSet inboxDS = new DataSet();
        inboxDS = inbox.GetInboxEntries(userId);
        grvInBox.DataSource = inboxDS;
        grvInBox.DataBind();
        
       
    }
    void PopulateAllInbox()
    {
          int userId = 0;
        if (Session["UserId"] != null)
            userId = Convert.ToInt16(Session["UserId"].ToString());
       // DataSet inboxDS = new DataSet();

        bool res = inbox.SearchInbox(advanceSearch, userId, out ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();


        //inboxDS = inbox.GetAllInboxEntries(userId);
        //GridView1.DataSource = inboxDS;
        //GridView1.DataBind();
    }

    protected void btnEdit1_Click(object sender, EventArgs e)
    {
        int currentStatusNo = 0;
        inboxType = "All";
        ImageButton ibtn1 = sender as ImageButton;
        string path = string.Empty;
        ImageButton btn = (ImageButton)sender;
        rowIndex = Convert.ToInt32(btn.Attributes["RowIndex"]);
        string recordNumber = ((Label)GridView1.Rows[rowIndex].FindControl("lblRecordNumber1")).Text;
        string requestType = ((Label)GridView1.Rows[rowIndex].FindControl("lblRequestTypeId1")).Text;
        string requestLink = ((Label)GridView1.Rows[rowIndex].FindControl("lblRequestLink1")).Text;

        string requesterName = ((Label)GridView1.Rows[rowIndex].FindControl("lblRequeserName1")).Text;
        string reqName = ((Label)GridView1.Rows[rowIndex].FindControl("lblReqName1")).Text;
        requestTypeId = Convert.ToInt16(requestType);
        int inboxUniqId = Convert.ToInt16(recordNumber);
        inboxLinkKey = Convert.ToInt16(requestLink);
        uniqInbox = inboxUniqId;
        string controlPathName = inbox.GetPathNameByRequestTypeAndUserId(requestTypeId, inboxUniqId);
        Session["controlPath"] = controlPathName;
        Session["hasrequestLinkId"] = inboxLinkKey;
        Session["requestTypeId"] = requestTypeId;
        // LastLoadedControl = controlPathName;
        // Session["UserManager_Control"] = controlPathName;
        LastLoadedControl = controlPathName;
        string currentStatusId = ((Label)GridView1.Rows[rowIndex].FindControl("lblCurrentStatus1")).Text;
        if (currentStatusId != "")
            currentStatusNo = Convert.ToInt16(currentStatusId);
        if (currentStatusNo == 1)
        {
            bool status = inbox.UpdateInboxStatusByRecordNumber(inboxUniqId, viewDate, processedDate, 2, txtComment.Text);
        }
        LoadUserControl();
        btnPrevious1.Visible = true;
        btnNext1.Visible = true;
        btnBackToinBox1.Visible = true;
        lblRequestTypeName1.Text = reqName;
        lblUserName1.Text = requesterName;
    }
    protected void btnEditPurchase_Click(object sender, EventArgs e)
    {
        int currentStatusNo = 0;
        inboxType = "Recent";
        //GridViewRow selectedRow = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
        //int intRowIndex = Convert.ToInt32(selectedRow.RowIndex);
        //GridView.Rows[intRowIndex].BackColor = System.Drawing.Color.Blue;
        ImageButton ibtn1 = sender as ImageButton;
        //  int rowIndex = Convert.ToInt32(ibtn1.Attributes["RowIndex"]);
        // Label lblMediaID_ =(Label)GridView1.Rows[RowIndex_].FindControl("lblMedia_ID");

        // string ProductID = lblMediaID_.Text;

        string path = string.Empty;
        ImageButton btn = (ImageButton)sender;
        //string[] CommandArgument = btn.CommandArgument.Split(',');
        //string recordNumber = CommandArgument[0];
        //string requestType = CommandArgument[1];
        //string requestLink = CommandArgument[2];
        //string rowIndexNo = CommandArgument[3];
        //rowIndex = Convert.ToInt32(rowIndexNo);
        rowIndex = Convert.ToInt32(btn.Attributes["RowIndex"]);
        string recordNumber = ((Label)grvInBox.Rows[rowIndex].FindControl("lblRecordNumber")).Text;
        string requestType = ((Label)grvInBox.Rows[rowIndex].FindControl("lblRequestTypeId")).Text;
        string requestLink = ((Label)grvInBox.Rows[rowIndex].FindControl("lblRequestLink")).Text;

        string requesterName = ((Label)grvInBox.Rows[rowIndex].FindControl("lblRequeserName")).Text;
        string reqName = ((Label)grvInBox.Rows[rowIndex].FindControl("lblReqName")).Text;
        requestTypeId = Convert.ToInt16(requestType);
        int inboxUniqId = Convert.ToInt16(recordNumber);
        inboxLinkKey = Convert.ToInt16(requestLink);
        uniqInbox = inboxUniqId;
        string controlPathName = inbox.GetPathNameByRequestTypeAndUserId(requestTypeId, inboxUniqId);
        Session["controlPath"] = controlPathName;
        Session["hasrequestLinkId"] = inboxLinkKey;
        Session["requestTypeId"] = requestTypeId;
        // LastLoadedControl = controlPathName;
        // Session["UserManager_Control"] = controlPathName;
        btnApprove.Visible = true;
        btnManualForward.Visible = true;
        btnNext.Visible = true;
        btnPrevious.Visible = true;
        btnReject.Visible = true;
        btnRequestInfo.Visible = true;
        lblComments.Visible = true;
        txtComment.Visible = true;
        LastLoadedControl = controlPathName;
        string currentStatusId = ((Label)grvInBox.Rows[rowIndex].FindControl("lblCurrentStatus")).Text;
        if (currentStatusId != "")
            currentStatusNo = Convert.ToInt16(currentStatusId);
        if (currentStatusNo == 1)
        {

            bool status = inbox.UpdateInboxStatusByRecordNumber(inboxUniqId, viewDate, processedDate, 2, txtComment.Text);
        }
        LoadUserControl();
        lblRequestTypeName.Text = reqName;
        lblUserName.Text = requesterName;

    }
    protected void btnApprove_Click(object sender, EventArgs e)
    {
        bool status = inbox.UpdateInboxStatusByRecordNumber(uniqInbox, viewDate, processedDate, 4, txtComment.Text);
        bool status1 = inbox.UpdateRequestLinkStatus(5, requestTypeId, inboxLinkKey,3);
        if (status)
        {
            MessageBox.Show("Successfully Approved the request");
            grvInBox.Visible = true;
            btnNext.Visible = false;
            btnPrevious.Visible = false;
            PopulateInBox();
            HideControls();
            Session["hasrequestLinkId"] = null;
            Session["requestTypeId"] = null; ;
            btnManualForward.Visible = true;
        }
        else
            MessageBox.Show("Failed to Approved the request");
    }
    protected void BtnSearch_Click(object sender, EventArgs e)
    {
    }
    protected void btnSearch1_Click(object sender, EventArgs e)
    {
    }
    protected void btnManualForward_Click(object sender, EventArgs e)
    {
        Session["UserManager_Control"] = "Purchase/ucManuallySendForApproval.ascx";
        Response.Redirect("BusinessProcessAutomation.aspx?linkKey=" + inboxLinkKey + "&RequestType=" + requestTypeId + "&RequestLinkId=" + uniqInbox);

    }
    protected void btnReject_Click(object sender, EventArgs e)
    {
        bool status = inbox.UpdateInboxStatusByRecordNumber(uniqInbox, viewDate, processedDate, 5, txtComment.Text);
        bool status1 = inbox.UpdateRequestLinkStatus(5, requestTypeId, inboxLinkKey,2);

        if (status)
        {
            MessageBox.Show("Rejected the Request");
            HideControls();
            grvInBox.Visible = true;
            btnNext.Visible = false;
            btnPrevious.Visible = false;
            PopulateInBox();
            Session["hasrequestLinkId"] = null;
            Session["requestTypeId"] = null; ;
        }
        else
            MessageBox.Show("Failed to Reject the request");
    }

    protected void btnRequestInfo_Click(object sender, EventArgs e)
    {
        bool status = inbox.UpdateInboxStatusByRecordNumber(uniqInbox, viewDate, processedDate, 3, txtComment.Text);
        bool status1 = inbox.UpdateRequestLinkStatus(4, requestTypeId, inboxLinkKey,2);

        if (status)
        {
            MessageBox.Show("Request More Information");
            HideControls();
            grvInBox.Visible = true;
            btnNext.Visible = false;
            btnPrevious.Visible = false;
            PopulateInBox();
            Session["hasrequestLinkId"] = null;
            Session["requestTypeId"] = null; ;
        }
        else
            MessageBox.Show("Failed to request the request");
    }


    private string LastLoadedControl
    {
        get
        {
            return ViewState["LastLoaded"] as string;
        }
        set
        {
            ViewState["LastLoaded"] = value;
        }
    }

    private void LoadUserControl()
    {
        string lastcontrolPath = LastLoadedControl;
        if (!string.IsNullOrEmpty(lastcontrolPath))
        {
            if (inboxType == "All")
            {
                GridView1.Visible = false;
                pnl.Visible = false;
                ucLoadUserControl1.Controls.Clear();
                UserControl uc = (UserControl)LoadControl(lastcontrolPath);
                ucLoadUserControl1.Controls.Add(uc);
            }
            else
            {
                grvInBox.Visible = false;
                ucLoadUserControl.Controls.Clear();
                UserControl uc = (UserControl)LoadControl(lastcontrolPath);
                ucLoadUserControl.Controls.Add(uc);
            }
        }


        //string lastcontrolPath = LastLoadedControl;
        //if (!string.IsNullOrEmpty(lastcontrolPath))
        //{
        //    mpePerson.Controls.Clear();
        //    UserControl uc = (UserControl)LoadControl(lastcontrolPath);
        //    pnlInBox.Controls.Add(uc);
        //    mpePerson.Show();
        //}
    }
    protected void HideControls()
    {
        lblComments.Visible = false;
        txtComment.Visible = false;
        btnApprove.Visible = false;
        btnReject.Visible = false;
        btnRequestInfo.Visible = false;
    }
    protected void btnBackToinBox_Click(object sender, EventArgs e)
    {
        Session["hasrequestLinkId"] = null;
        Session["requestTypeId"] = null;
        Session["UserManager_Control"] = "TaskList.ascx";
        Response.Redirect("BusinessProcessAutomation.aspx");

    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        int grdRowCount = grvInBox.Rows.Count - 1;
        if (grdRowCount > rowIndex)
        {
            //pnlMain.Controls.Clear();
            rowIndex = rowIndex + 1;
            LoadNextAndPrevius();
        }
        else
        {
            LoadNextAndPrevius();
            MessageBox.Show("No records");

        }

    }
    protected void btnPrevious_Click(object sender, EventArgs e)
    {
        if (rowIndex > 0)
        {
            // pnlMain.Controls.Clear();
            rowIndex = rowIndex - 1;
            LoadNextAndPrevius();
        }
        else
        {
            LoadNextAndPrevius();
            MessageBox.Show("No records");
        }

    }

    protected void LoadNextAndPrevius()
    {
        int currentStatusNo=0;
        string recordNumber = ((Label)grvInBox.Rows[rowIndex].FindControl("lblRecordNumber")).Text;
        string requestType = ((Label)grvInBox.Rows[rowIndex].FindControl("lblRequestTypeId")).Text;
        string requestLink = ((Label)grvInBox.Rows[rowIndex].FindControl("lblRequestLink")).Text;
        int requestTypeId = Convert.ToInt16(requestType);
        int inboxUniqId = Convert.ToInt16(recordNumber);
        int inboxLinkKey = Convert.ToInt16(requestLink);

        string requesterName = ((Label)grvInBox.Rows[rowIndex].FindControl("lblRequeserName")).Text;
        string reqName = ((Label)grvInBox.Rows[rowIndex].FindControl("lblReqName")).Text;

        uniqInbox = inboxUniqId;
        string controlPathName = inbox.GetPathNameByRequestTypeAndUserId(requestTypeId, inboxUniqId);
        Session["controlPath"] = controlPathName;
        Session["hasrequestLinkId"] = inboxLinkKey;
        Session["requestTypeId"] = requestTypeId;
        // LastLoadedControl = controlPathName;
        //  Session["UserManager_Control"] = controlPathName;
        LastLoadedControl = controlPathName;
        string currentStatusId = ((Label)grvInBox.Rows[rowIndex].FindControl("lblCurrentStatus")).Text;
        if (currentStatusId != "")
            currentStatusNo = Convert.ToInt16(currentStatusId);
        if (currentStatusNo == 1)
        {
            bool status = inbox.UpdateInboxStatusByRecordNumber(inboxUniqId, viewDate, processedDate, 2, txtComment.Text);
        }
        LoadUserControl();
        lblUserName.Text = requesterName;
        lblRequestTypeName.Text = reqName;
    }



    protected void grvInBox_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        foreach (GridViewRow gvr in grvInBox.Rows)
        {
            int statusId = 0;
            string lblCurrentStatus = ((Label)gvr.FindControl("lblCurrentStatus")).Text;
            if (lblCurrentStatus != "")
                statusId = Convert.ToInt16(lblCurrentStatus);

            if (statusId == 1)
            {
                gvr.Font.Bold = true;
                gvr.Font.Name = "Verdana";
                gvr.ForeColor = Color.Green;
            }
            else if (statusId == 2)
            {
                gvr.Font.Bold = false;
                gvr.Font.Name = "Verdana";
                gvr.ForeColor = Color.FromName("#22316C");

            }
        }


        GridView gridView = (GridView)sender;

        if (gridView.SortExpression.Length > 0)
        {
            int cellIndex = -1;
            foreach (DataControlField field in gridView.Columns)
            {
                if (field.SortExpression == gridView.SortExpression)
                {
                    cellIndex = gridView.Columns.IndexOf(field);
                    break;
                }
            }

            if (cellIndex > -1)
            {
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    //  this is a header row,
                    //  set the sort style
                    e.Row.Cells[cellIndex].CssClass = gridView.SortDirection == SortDirection.Ascending ? "sortascheaderstyle" : "sortdescheaderstyle";
                }
                else if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    //  this is an alternating row
                    e.Row.Cells[cellIndex].CssClass = e.Row.RowIndex % 2 == 0 ? "sortalternatingrowstyle" : "sortrowstyle";
                }
            }
        }

        if (e.Row.RowType == DataControlRowType.Pager)
        {
            Label lblTotalNumberOfPages = (Label)e.Row.FindControl("lblTotalNumberOfPages");
            lblTotalNumberOfPages.Text = gridView.PageCount.ToString();

            TextBox txtGoToPage = (TextBox)e.Row.FindControl("txtGoToPage");
            txtGoToPage.Text = (gridView.PageIndex + 1).ToString();

            // DropDownList ddlPageSize = (DropDownList)e.Row.FindControl("ddlPageSize");
            // ddlPageSize.SelectedValue = gridView.PageSize.ToString();
        }
    }

    protected void btnDeleteBomList_Click(object sender, EventArgs e)
    {
        ImageButton btn = (ImageButton)sender;
        string recordNumber = btn.CommandArgument;
        int recordNo = Convert.ToInt16(recordNumber);
        bool status = inbox.DeleteInBoxEntries(recordNo);
        if (status)
        {
            PopulateInBox();
            MessageBox.Show("Successfully deleted");
        }
        else
        {
            MessageBox.Show("Failed to delete Inbox Entries");
        }
    }
    protected void grvInBox_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        grvInBox.PageIndex = e.NewPageIndex;
        PopulateInBox();
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GoToPage_TextChanged(object sender, EventArgs e)
    {
        TextBox txtGoToPage = (TextBox)sender;

        int pageNumber;
        if (int.TryParse(txtGoToPage.Text.Trim(), out pageNumber) && pageNumber > 0 && pageNumber <= this.grvInBox.PageCount)
        {
            this.grvInBox.PageIndex = pageNumber - 1;
        }
        else
        {
            this.grvInBox.PageIndex = 0;
        }
    }


    protected void grvInBox_SelectedIndexChanged(object sender, EventArgs e)
    {


    }
    protected void rblCriteria_SelectedIndexChanged(object sender, EventArgs e)
    {
        AdvancedSerch();
    }
   
    protected void ddlSelect_SelectedIndexChanged(object sender, EventArgs e)
    {

       // ImageButton1.Enabled = true; ;
        ddlSelect.Enabled = true;
        ddlStatus.Enabled = false;
        txtDateOfCreation.Enabled = true;
        txtrequestor.Enabled = false;
        ddlRequestTypeAll.SelectedIndex=0;
        advanceSearch.FirstName = string.Empty;
        txtDate.Text = string.Empty;
        if (ddlSelect.SelectedItem.ToString() == "Between")
        {
           // ImageButton2.Enabled = true; ;
            txtDate.Enabled = true;
            advanceSearch.DateofCreation1 = txtDate.Text.Trim();
        }
        else
        {

            advanceSearch.DateofCreation = txtDateOfCreation.Text.Trim();
            advanceSearch.FirstName = string.Empty;
            advanceSearch.Status = 0;
            if (ddlSelect.SelectedIndex != 0)
                advanceSearch.DateStatus = ddlSelect.SelectedItem.ToString();
            else
                advanceSearch.DateStatus = "0";
        }
    }
    protected void AdvancedSerch()
    {
        string ee = txtrequestor.Text;

        if (rblCriteria.SelectedItem.ToString() == "RequestType")
        {
            txtDate.Text = string.Empty;
            txtDateOfCreation.Text = string.Empty;
            ddlSelect.SelectedIndex = 0;
            txtrequestor.Text = string.Empty;
            ddlStatus.SelectedIndex = 0;
            ddlRequestTypeAll.Enabled = true;
            txtrequestor.Enabled = false;
            ddlStatus.Enabled = false;
            txtDate.Enabled = false;
            txtDateOfCreation.Enabled = false;
            if (ddlRequestTypeAll.SelectedIndex != 0)
                advanceSearch.RequestType = Convert.ToInt16(ddlRequestTypeAll.SelectedValue);
            else
                advanceSearch.RequestType = 0;
            advanceSearch.Status = 0;
            advanceSearch.FirstName = string.Empty;
            advanceSearch.DateStatus = "0";
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.DateofCreation1 = string.Empty;
        }
        else if (rblCriteria.SelectedItem.ToString() == "Requester")
        {
            txtDate.Text = string.Empty;
            txtDateOfCreation.Text = string.Empty;
            ddlSelect.SelectedIndex = 0;
            ddlStatus.SelectedIndex = 0;
            ddlRequestTypeAll.SelectedIndex = 0;
            ddlRequestTypeAll.Enabled = false;
            txtrequestor.Enabled = true;
            ddlStatus.Enabled = false;
            txtDate.Enabled = false;
            txtDateOfCreation.Enabled = false;
            advanceSearch.RequestType = 0;
            advanceSearch.Status = 0;
            advanceSearch.FirstName = txtrequestor.Text.Trim();
            advanceSearch.DateStatus = "0";
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.DateofCreation1 = string.Empty;

        }
        else if (rblCriteria.SelectedItem.ToString() == "Status")
        {
            txtDate.Text = string.Empty;
            txtDateOfCreation.Text = string.Empty;
            ddlSelect.SelectedIndex = 0;
            txtrequestor.Text = string.Empty;
            ddlRequestTypeAll.SelectedIndex = 0;
            ddlRequestTypeAll.Enabled = false;
            txtrequestor.Enabled = false;
            ddlStatus.Enabled = true;
            txtDate.Enabled = false;
            txtDateOfCreation.Enabled = false;
            if (ddlStatus.SelectedIndex != 0)
                advanceSearch.Status = Convert.ToInt16(ddlStatus.SelectedValue);
            else
                advanceSearch.Status = 0;
            advanceSearch.FirstName = string.Empty;
            advanceSearch.DateStatus = "0";
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.DateofCreation1 = string.Empty;

        }
        else if (rblCriteria.SelectedItem.ToString() == "Date")
        {
            ddlStatus.SelectedIndex = 0;
            ddlRequestTypeAll.SelectedIndex = 0;
            txtDateOfCreation.Enabled = true;
            ddlSelect.Enabled = true;
            txtrequestor.Enabled = false;
            ddlRequestTypeAll.Enabled = false;
            ddlStatus.Enabled = false;
            txtrequestor.Text = string.Empty;

            if (ddlSelect.SelectedItem.ToString() == "Between")
            {
               // ImageButton2.Enabled = true; ;
                txtDate.Enabled = true;
                advanceSearch.DateofCreation = txtDateOfCreation.Text.Trim();
                advanceSearch.DateofCreation1 = txtDate.Text.Trim();
                advanceSearch.FirstName = string.Empty;
                advanceSearch.RequestType = 0;
                advanceSearch.Status = 0;
                if (ddlSelect.SelectedIndex != 0)
                    advanceSearch.DateStatus = ddlSelect.SelectedItem.ToString();
                else
                    advanceSearch.DateStatus = "0";
    
            }
            else
            {

                advanceSearch.DateofCreation = txtDateOfCreation.Text.Trim();
                advanceSearch.FirstName = string.Empty;
                advanceSearch.RequestType = 0;
                advanceSearch.Status = 0;
                if (ddlSelect.SelectedIndex != 0)
                    advanceSearch.DateStatus = ddlSelect.SelectedItem.ToString();
                else
                    advanceSearch.DateStatus = "0";
            }
        }
        else
        {
            txtDate.Enabled = false;
            txtDateOfCreation.Text = string.Empty;
            txtrequestor.Text = string.Empty;
            ddlStatus.SelectedIndex = 0;
            ddlStatus.Enabled = false;
            txtDateOfCreation.Enabled = false;
            txtrequestor.Enabled = false;
            ddlRequestTypeAll.SelectedIndex = 0;
            ddlRequestTypeAll.Enabled = false;
            advanceSearch.FirstName = string.Empty;
            advanceSearch.DateofCreation = string.Empty;
            advanceSearch.RequestType = 0;
            advanceSearch.Status = 0;
        }
        
       
        }

    protected void btnGo_Click(object sender, EventArgs e)
    {
        if (rblCriteria.SelectedItem != null)
        {
            AdvancedSerch();
        }
        PopulateAllInbox();
    }
    protected void btnPrevious1_Click(object sender, EventArgs e)
    {
        if (rowIndex > 0)
        {
            // pnlMain.Controls.Clear();
            rowIndex = rowIndex - 1;
            LoadNextAndPreviusAll();
        }
        else
        {
            LoadNextAndPreviusAll();
            MessageBox.Show("No records");
        }
    }

    protected void btnBackToinBox1_Click(object sender, EventArgs e)
    {
        inboxType = string.Empty;
        Session["hasrequestLinkId"] = null;
        Session["requestTypeId"] = null;
        Session["UserManager_Control"] = "TaskList.ascx";
        Response.Redirect("BusinessProcessAutomation.aspx");

    }

    protected void btnNext1_Click(object sender, EventArgs e)
    {
        int grdRowCount = GridView1.Rows.Count - 1;
        if (grdRowCount > rowIndex)
        {
            //pnlMain.Controls.Clear();
            rowIndex = rowIndex + 1;
            LoadNextAndPreviusAll();
        }
        else
        {
            LoadNextAndPreviusAll();
            MessageBox.Show("No records");

        }
    }

    protected void btnApprove1_Click(object sender, EventArgs e)
    {
    }

    protected void btnReject1_Click(object sender, EventArgs e)
    {
    }

    protected void btnRequestInfo1_Click(object sender, EventArgs e)
    {
    }

    protected void LoadNextAndPreviusAll()
    {
        int currentStatusNo = 0;
        string recordNumber = ((Label)GridView1.Rows[rowIndex].FindControl("lblRecordNumber1")).Text;
        string requestType = ((Label)GridView1.Rows[rowIndex].FindControl("lblRequestTypeId1")).Text;
        string requestLink = ((Label)GridView1.Rows[rowIndex].FindControl("lblRequestLink1")).Text;
        int requestTypeId = Convert.ToInt16(requestType);
        int inboxUniqId = Convert.ToInt16(recordNumber);
        int inboxLinkKey = Convert.ToInt16(requestLink);

        string requesterName = ((Label)GridView1.Rows[rowIndex].FindControl("lblRequeserName1")).Text;
        string reqName = ((Label)GridView1.Rows[rowIndex].FindControl("lblReqName1")).Text;

        uniqInbox = inboxUniqId;
        string controlPathName = inbox.GetPathNameByRequestTypeAndUserId(requestTypeId, inboxUniqId);
        Session["controlPath"] = controlPathName;
        Session["hasrequestLinkId"] = inboxLinkKey;
        Session["requestTypeId"] = requestTypeId;
        // LastLoadedControl = controlPathName;
        //  Session["UserManager_Control"] = controlPathName;
        LastLoadedControl = controlPathName;
        string currentStatusId = ((Label)GridView1.Rows[rowIndex].FindControl("lblCurrentStatus1")).Text;
        if (currentStatusId != "")
            currentStatusNo = Convert.ToInt16(currentStatusId);
        if (currentStatusNo == 1)
        {
            bool status = inbox.UpdateInboxStatusByRecordNumber(inboxUniqId, viewDate, processedDate, 2, txtComment.Text);
        }
        LoadUserControl();
        lblUserName1.Text = requesterName;
        lblRequestTypeName1.Text = reqName;
    }

   
    }
